package com.gzdh.tang.dishrecognition.controller;

import com.alibaba.fastjson.JSONObject;
import com.gzdh.tang.comm.vo.Result;
import com.gzdh.tang.dishrecognition.entity.MacMainpFoodMenu;
import com.gzdh.tang.dishrecognition.service.MacMainpFoodMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("dr/foods/menu")
public class DrFoodsMenuController {


    @Autowired
    MacMainpFoodMenuService macMainpFoodMenuService;

    @GetMapping("list")
    public Result<Object> list() {
        Result<Object> result = new Result<>();
        List<MacMainpFoodMenu> macMainpFoodMenuList = macMainpFoodMenuService.list();
        result.setResult(macMainpFoodMenuList);
        return result;
    }

    @PostMapping("add")
    public Result<Object> addMenu(@RequestBody JSONObject jsonObject) {
        Result<Object> result = new Result<>();
        String name = jsonObject.getString("name");
        String price = jsonObject.getString("price");
        MacMainpFoodMenu macMainpFoodMenu = new MacMainpFoodMenu();
        macMainpFoodMenu.setName(name);
        macMainpFoodMenu.setPrice(price);
        macMainpFoodMenuService.save(macMainpFoodMenu);
        return result;
    }

    @PostMapping("update")
    public Result<Object> update(@RequestBody MacMainpFoodMenu macMainpFoodMenu) {
        Result<Object> result = new Result<>();
        macMainpFoodMenuService.updateById(macMainpFoodMenu);
        return result;
    }


}
